﻿Imports System.Data.SqlClient

Public Class clsCuboContables
    Private mstrEmpresa As String
    Private mstrAbreviacion As String
    Private mintEjercicio As Integer
    Private mintPeriodo As Integer
    Private mstrCodigo As String
    Private mstrNombre As String
    Private mstrCuenta As String
    Private mintCInforme As Integer
    Private mintCImpuestos As Integer
    Private mstrTitulo As String
    Private mstrSubTitulo As String
    Private mstrMayor As String
    Private mintIdOriginal As Integer
    Private mdblCargos As Double
    Private mdblAbonos As Double
    Private mdblSaldo As Double

    Public Property Empresa() As String
        Get
            Return mstrEmpresa
        End Get
        Set(ByVal value As String)
            mstrEmpresa = value
        End Set
    End Property
    Public Property Abreviacion() As String
        Get
            Return mstrAbreviacion
        End Get
        Set(ByVal value As String)
            mstrAbreviacion = value
        End Set
    End Property
    Public Property Ejercicio() As Integer
        Get
            Return mintEjercicio
        End Get
        Set(ByVal value As Integer)
            mintEjercicio = value
        End Set
    End Property
    Public Property Periodo() As Integer
        Get
            Return mintPeriodo
        End Get
        Set(ByVal value As Integer)
            mintPeriodo = value
        End Set
    End Property
    Public Property Codigo() As String
        Get
            Return mstrCodigo
        End Get
        Set(ByVal value As String)
            mstrCodigo = value
        End Set
    End Property
    Public Property Nombre() As String
        Get
            Return mstrNombre
        End Get
        Set(ByVal value As String)
            mstrNombre = value
        End Set
    End Property
    Public Property Cuenta() As String
        Get
            Return mstrCuenta
        End Get
        Set(ByVal value As String)
            mstrCuenta = value
        End Set
    End Property
    Public Property CInforme() As Integer
        Get
            Return mintCInforme
        End Get
        Set(ByVal value As Integer)
            mintCInforme = value
        End Set
    End Property
    Public Property CImpuestos() As Integer
        Get
            Return mintCImpuestos
        End Get
        Set(ByVal value As Integer)
            mintCImpuestos = value
        End Set
    End Property
    Public Property Titulo() As String
        Get
            Return mstrTitulo
        End Get
        Set(ByVal value As String)
            mstrTitulo = value
        End Set
    End Property
    Public Property Subtitulo() As String
        Get
            Return mstrSubTitulo
        End Get
        Set(ByVal value As String)
            mstrSubTitulo = value
        End Set
    End Property
    Public Property Mayor() As String
        Get
            Return mstrMayor
        End Get
        Set(ByVal value As String)
            mstrMayor = value
        End Set
    End Property
    Public Property IdOriginal() As Integer
        Get
            Return mintIdOriginal
        End Get
        Set(ByVal value As Integer)
            mintIdOriginal = value
        End Set
    End Property
    Public Property Cargos() As Double
        Get
            Return mdblCargos
        End Get
        Set(ByVal value As Double)
            mdblCargos = value
        End Set
    End Property
    Public Property Abonos() As Double
        Get
            Return mdblAbonos
        End Get
        Set(ByVal value As Double)
            mdblAbonos = value
        End Set
    End Property
    Public Property Saldo() As Double
        Get
            Return mdblSaldo
        End Get
        Set(ByVal value As Double)
            mdblSaldo = value
        End Set
    End Property
    Public Sub New()
        mstrEmpresa = ""
        mstrAbreviacion = ""
        mintEjercicio = 0
        mintPeriodo = 0
        mstrCodigo = ""
        mstrNombre = ""
        mstrCuenta = ""
        mintCInforme = 0
        mintCImpuestos = 0
        mstrTitulo = ""
        mstrSubTitulo = ""
        mstrMayor = ""
        mintIdOriginal = 0
        mdblAbonos = 0
        mdblCargos = 0
        mdblSaldo = 0
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into CuboContables (" & _
                            "Empresa," & _
                            "Abreviacion," & _
                            "Ejercicio," & _
                            "Periodo," & _
                            "Codigo," & _
                            "Nombre," & _
                            "Cuenta," & _
                            "CInforme," & _
                            "CImpuestos," & _
                            "Titulo," & _
                            "Subtitulo," & _
                            "Mayor, " & _
                            "IdOriginal, " & _
                            "Cargos," & _
                            "Abonos," & _
                            "Saldo)" & _
                            "VALUES (" & _
                            "substring(@Empresa,1,300)," & _
                            "substring(@Abreviacion,1,10)," & _
                            "@Ejercicio," & _
                            "@Periodo," & _
                            "substring(@Codigo,1,30)," & _
                            "substring(@Nombre,1,50)," & _
                            "substring(@Cuenta,1,90)," & _
                            "@CInforme," & _
                            "@CImpuestos," & _
                            "substring(@Titulo,1,90)," & _
                            "substring(@Subtitulo,1,90)," & _
                            "substring(@Mayor,1,90)," & _
                            "@IdOriginal," & _
                            "@Cargos," & _
                            "@Abonos," & _
                            "@Saldo)"


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("Empresa", mstrEmpresa)
        Command.Parameters.AddWithValue("Abreviacion", mstrAbreviacion)
        Command.Parameters.AddWithValue("Ejercicio", mintEjercicio)
        Command.Parameters.AddWithValue("Periodo", mintPeriodo)
        Command.Parameters.AddWithValue("Codigo", mstrCodigo)
        Command.Parameters.AddWithValue("Nombre", mstrNombre)
        Command.Parameters.AddWithValue("Cuenta", mstrCuenta)
        Command.Parameters.AddWithValue("CInforme", mintCInforme)
        Command.Parameters.AddWithValue("CImpuestos", mintCImpuestos)
        Command.Parameters.AddWithValue("Titulo", mstrTitulo)
        Command.Parameters.AddWithValue("Subtitulo", mstrSubTitulo)
        Command.Parameters.AddWithValue("Mayor", mstrMayor)
        Command.Parameters.AddWithValue("IdOriginal", mintIdOriginal)
        Command.Parameters.AddWithValue("Cargos", mdblCargos)
        Command.Parameters.AddWithValue("Abonos", mdblAbonos)
        Command.Parameters.AddWithValue("Saldo", mdblSaldo)

        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
End Class
